package org.permission.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.permission.dao.SysPermissionDao;
import org.permission.pojo.SysPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sysPermission")
public class SysPermissionController {
	@Autowired
	private SysPermissionDao sysPermissionDao;

	public void setSysPermissionDao(SysPermissionDao sysPermissionDao) {
		this.sysPermissionDao = sysPermissionDao;
	}
	
	@RequestMapping("/all")
	public List<SysPermission> searchAll() throws Exception {
		return sysPermissionDao.getAll();
	}
	
	@RequestMapping("/index")
	public String index() throws Exception {
		return "sysPermission/index";
	}
	
	@RequestMapping("/list")
	@ResponseBody
	public List<SysPermission> list() throws Exception {
		List<SysPermission> list = sysPermissionDao.getAllPers();
		return list;
	}
	
	@RequestMapping(value="/form",method=RequestMethod.GET)
	public String add() throws Exception {
		return "sysPermission/form";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(SysPermission sysPermission) throws Exception {
		Map<String, Object> map = new HashMap<>();
		sysPermissionDao.add(sysPermission);
		map.put("result", true);
		return map;
	}
	
	@RequestMapping(value="/batchDelete")
	@ResponseBody
	public Map<String, Object> batchDelete(Integer[] ids) throws Exception {
		Map<String, Object> map = new HashMap<>();
		sysPermissionDao.batchDelete(ids);
		map.put("result", true);
		return map;
	}
	
	@RequestMapping("/view/{id}")
	@ResponseBody
	public SysPermission view(@PathVariable Integer id) throws Exception {
		return sysPermissionDao.get(id);
	}
	
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(SysPermission sysPermission) throws Exception {
		Map<String, Object> map = new HashMap<>();
		sysPermissionDao.update(sysPermission);
		map.put("result", true);
		return map;
	} 
	
	
	
}
